Wiki

Clone wiki

WebAutomation / Activities & Attributes

An activity is a set of actions which can be associated with Component or Container. Those actions occur during loading a container (by using atDriver.Get<YourPage>()) and can depend on used attributes. Activities which are not associated with any attributes are always executed during loading a container.

Since version 1.1.180.0, you can also define "OnAction" activities, which will be executed before and/or after performing an action on Web Component.

Below diagram illustrates basic flow in WebAutomation framework Flow.png

Custom attributes & activities

Besides the basic set of activities (which are provided by the framework together with predefined attributes), you can define your own custom activities. To do so, create a class that implements IWebContainerActivity, IWebComponentActivity or IOnActionActivity and register it by usng ExtensionManager.

var atDriver = AutomationDriverFactory.Get();
atDriver.Extensions.RegisterActivity<YourActivity>();

Registration should be done before loading the Web Container / performing an action - usually in a method where the AutomationDriver is created.

Activity without the attribute

using System;
using System.IO;
using OpenQA.Selenium;
using WebAutomation.Core.WebObjects.WebContainer.Activities;

// Activity which saves html sources from all visited pages.
public class SaveSourcesActivity : IWebContainerActivity
{
    public Type RequiredAttributeType
    {
        get
        {
            // No attribute is required
            // Activity will be executed for all Web Containers
            return null;
        }
    }

    public void Perform(object webContainer, IWebDriver webDriver, string attributeValue = null)
    {
        // Your implementation      
        string pageSource = webDriver.PageSource;
        string filename = string.Format("{0}.txt", webContainer.GetType().Name);
        File.WriteAllText(filename, pageSource);
    }
}

Activity with an attribute

  • Create a new class for attribute
    public class CustomAttribute : WebComponentAttribute
    {
        public CustomAttribute(string value)
        {
            this.Value = value;
        }
    
        public string Value { get; set; }
    }
    
  • Use the custom attribute in XML file
    <component name="NameTextbox" id="name" custom="some value" />
    
  • Regenerate C# classes based on XML (run custom tool). Before doing that, please make sure that customAttributesNamespace (in .tt file) contains the namespace where the attribute is defined.
  • Create an activity for the attribute
    using OpenQA.Selenium;
    using System;
    using WebAutomation.Core.WebObjects.WebComponents;
    using WebAutomation.Core.WebObjects.WebComponents.Activities;
    
    // Activity which sends text to all Web Components marked with an attribute.
    public class FillValueActivity : IWebComponentActivity
    {
        public Type RequiredAttributeType
        {
            get
            {
                // Activity will be executed only for those components, which use the attribbute
                return typeof(CustomAttribute);
            }
        }
    
        public void Perform(IWebComponent webComponent, IWebDriver webDriver, string attributeValue = null)
        {
            // Your implementation
            string newValue = attributeValue;
            webComponent.Perform.Fill(newValue); 
        }
    }
    

Updated